home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00014_VTLgame Parent.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  11.9 KB  |  360 lines

  1. property firstTileChannel, firstTargetChannel, firstTileBmap, tilePointList, howManyCorrect, dragFlag, targetPointList, dragChan, selection, originalChannel, constrainChan, errorBuffer, enabled, tileList
  2. global gActorList, gHiddenActorList, gLevelObject, gUserObject, gGasGaugeObject, gMenuObject, gAwardsObject, gQTViewerObject, gVTLobject, gCDpath, gFileSep
  3.  
  4. on birth me
  5.   set enabled to 0
  6.   set firstTileChannel to 16
  7.   set firstTargetChannel to 4
  8.   set constrainChan to 1
  9.   set dragChan to 48
  10.   set firstTileBmap to the number of cast "NumTimeline" + 1
  11.   set tilePointList to [point(228, 43), point(328, 43), point(427, 43), point(228, 131), point(328, 131), point(427, 131), point(228, 222), point(328, 222), point(427, 222)]
  12.   set targetPointList to [point(85, 314), point(143, 314), point(201, 314), point(259, 314), point(317, 314), point(375, 314), point(433, 314), point(491, 314), point(549, 314)]
  13.   set dragFlag to 0
  14.   newVTLgame(me)
  15.   return me
  16. end
  17.  
  18. on setup me
  19.   add(gActorList, birth(script "Rollover Anim Button Class", "goMenu( gVTLgameObject, me )", 27, 27, 5, "RCA-07VO01", "RCA-07RO01"))
  20.   add(gActorList, birth(script "Rollover Anim Button Class", "help( gVTLgameobject, me )", 28, 28, 11, EMPTY, "RCA-05RO02"))
  21. end
  22.  
  23. on update me
  24.   if not soundBusy(1) then
  25.     puppetSound(0)
  26.   end if
  27.   set the locH of sprite dragChan to the mouseH
  28.   set the locV of sprite dragChan to the mouseV
  29.   puppetTempo(60)
  30. end
  31.  
  32. on goVTLgame me
  33.   clearAllActors()
  34.   unpuppetAll()
  35.   puppetPalette("VTLpal")
  36.   go("Grass")
  37.   go(the frame + 1)
  38.   puppetPalette("VTLgamePal", 60)
  39.   updateStage()
  40.   puppetPalette(0)
  41.   unLoadCast()
  42.   set VTLgameFrame to "VTLg" & string(the level of gLevelObject)
  43.   predrawVTLgameTiles(me)
  44.   go(VTLgameFrame)
  45. end
  46.  
  47. on saveVTLgame me
  48.   set VTLgameString to string(enabled) & ","
  49.   if enabled then
  50.     set VTLgameString to VTLgameString & string(howManyCorrect) & ","
  51.     repeat with tileObject in tileList
  52.       set VTLgameString to VTLgameString & save(tileObject)
  53.     end repeat
  54.   end if
  55.   return VTLgameString
  56. end
  57.  
  58. on loadVTLgame me, index
  59.   set enabled to value(item index of the dataString of gMenuObject)
  60.   set index to index + 1
  61.   if enabled = 1 then
  62.     set howManyCorrect to value(item index of the dataString of gMenuObject)
  63.     set index to index + 1
  64.     set tileList to []
  65.     repeat with whichTile = 1 to 9
  66.       set randomPos to value(item index of the dataString of gMenuObject)
  67.       set index to index + 1
  68.       set placedPos to value(item index of the dataString of gMenuObject)
  69.       set index to index + 1
  70.       add(tileList, birth(script "VTLtile Parent", whichTile, randomPos, placedPos))
  71.     end repeat
  72.   end if
  73.   return index
  74. end
  75.  
  76. on newVTLgame me
  77.   set scrambledList to shuffleList([1, 2, 3, 4, 5, 6, 7, 8, 9])
  78.   set tileList to []
  79.   repeat with tile = 1 to 9
  80.     set scrambledPos to getPos(scrambledList, tile)
  81.     add(tileList, birth(script "VTLtile Parent", tile, scrambledPos, 0))
  82.   end repeat
  83.   set errorBuffer to []
  84.   set howManyCorrect to 0
  85. end
  86.  
  87. on placeTile me
  88.   set targetLocChan to firstTargetChannel + selection - 1
  89.   set tileObject to getAt(tileList, selection)
  90.   set originPoint to getAt(tilePointList, the scrambledPos of tileObject)
  91.   if the level of gLevelObject = 3 then
  92.     repeat with possibleTarget = firstTargetChannel to firstTargetChannel + 8
  93.       if rollOver(possibleTarget) then
  94.         set placed to 1
  95.         exit repeat
  96.       end if
  97.     end repeat
  98.     if placed = 1 then
  99.       set newPos to possibleTarget - firstTargetChannel + 1
  100.       if slotOccupied(me, newPos) then
  101.         animateSprite(dragChan, originPoint, 5)
  102.         turnDone(me)
  103.       else
  104.         animateSprite(dragChan, point(the locH of sprite possibleTarget, the locV of sprite possibleTarget), 1)
  105.         set the timeLinePos of tileObject to newPos
  106.         if possibleTarget = targetLocChan then
  107.           set howManyCorrect to howManyCorrect + 1
  108.         end if
  109.         turnDone(me)
  110.         checkForSuccess(me)
  111.       end if
  112.     else
  113.       animateSprite(dragChan, originPoint, 5)
  114.       turnDone(me)
  115.     end if
  116.   else
  117.     if rollOver(targetLocChan) then
  118.       set the timeLinePos of tileObject to targetLocChan - firstTargetChannel + 1
  119.       set howManyCorrect to howManyCorrect + 1
  120.       animateSprite(dragChan, point(the locH of sprite targetLocChan, the locV of sprite targetLocChan), 1)
  121.     else
  122.       animateSprite(dragChan, originPoint, 5)
  123.       if the level of gLevelObject = 1 then
  124.         add(errorBuffer, selection)
  125.         if count(errorBuffer) = 3 then
  126.           if (getAt(errorBuffer, 1) = getAt(errorBuffer, 2)) and (getAt(errorBuffer, 2) = getAt(errorBuffer, 3)) then
  127.             sound playFile 1, gCDpath & "SOUND" & gFileSep & "GLOBAL" & gFileSep & "0820VO"
  128.             repeat while soundBusy(1)
  129.             end repeat
  130.             puppetSound(0)
  131.             set the timeLinePos of tileObject to targetLocChan - firstTargetChannel + 1
  132.             set howManyCorrect to howManyCorrect + 1
  133.             set errorBuffer to []
  134.             animateSprite(dragChan, point(the locH of sprite targetLocChan, the locV of sprite targetLocChan), 3)
  135.           else
  136.             deleteAt(errorBuffer, 1)
  137.           end if
  138.         end if
  139.       end if
  140.     end if
  141.     turnDone(me)
  142.     checkForSuccess(me)
  143.   end if
  144. end
  145.  
  146. on slotOccupied me, newPos
  147.   set occupiedFlag to 0
  148.   repeat with tile in tileList
  149.     if the timeLinePos of tile = newPos then
  150.       set occupiedFlag to 1
  151.       exit repeat
  152.     end if
  153.   end repeat
  154.   return occupiedFlag
  155. end
  156.  
  157. on doneButton me
  158.   if buttonHandler() = 1 then
  159.     startBuffering()
  160.     puppetSound("DoneSound")
  161.     updateStage()
  162.     set wrongList to []
  163.     repeat with tileObject in tileList
  164.       if wrong(tileObject) then
  165.         add(wrongList, tileObject)
  166.       end if
  167.     end repeat
  168.     if count(wrongList) > 0 then
  169.       set returnList to [0, 0, 0, 0, 0, 0, 0, 0, 0]
  170.       repeat with wrongTile in wrongList
  171.         setAt(returnList, the timeLinePos of wrongTile, wrongTile)
  172.       end repeat
  173.       repeat with tileObject in returnList
  174.         if objectp(tileObject) then
  175.           set the timeLinePos of tileObject to 0
  176.           set channel to firstTileChannel + the scrambledPos of tileObject - 1
  177.           set the castNum of sprite dragChan to the castNum of sprite channel
  178.           set the locH of sprite dragChan to the locH of sprite channel
  179.           set the locV of sprite dragChan to the locV of sprite channel
  180.           set the locH of sprite channel to 1000
  181.           updateStage()
  182.           animateSprite(dragChan, getAt(tilePointList, the scrambledPos of tileObject), 3)
  183.           set the castNum of sprite dragChan to the castNum of sprite channel
  184.           set the locH of sprite channel to the locH of sprite dragChan
  185.           set the locV of sprite channel to the locV of sprite dragChan
  186.           set the locH of sprite dragChan to 1000
  187.           updateStage()
  188.         end if
  189.       end repeat
  190.       repeat while soundBusy(0)
  191.       end repeat
  192.       puppetSound(0)
  193.     else
  194.       checkForSuccess(me)
  195.     end if
  196.     flushBuffer()
  197.   end if
  198. end
  199.  
  200. on resetVTLgame me
  201.   if buttonHandler() = 1 then
  202.     startBuffering()
  203.     puppetSound("RESETVTL")
  204.     updateStage()
  205.     set returnList to [0, 0, 0, 0, 0, 0, 0, 0, 0]
  206.     repeat with tileObject in tileList
  207.       set timeLinePos to the timeLinePos of tileObject
  208.       if timeLinePos > 0 then
  209.         setAt(returnList, timeLinePos, tileObject)
  210.       end if
  211.     end repeat
  212.     repeat with tileObject in returnList
  213.       if objectp(tileObject) then
  214.         set channel to firstTileChannel + the scrambledPos of tileObject - 1
  215.         set the castNum of sprite dragChan to the castNum of sprite channel
  216.         set the locH of sprite dragChan to the locH of sprite channel
  217.         set the locV of sprite dragChan to the locV of sprite channel
  218.         set the locH of sprite channel to 1000
  219.         updateStage()
  220.         animateSprite(dragChan, getAt(tilePointList, the scrambledPos of tileObject), 3)
  221.         set the castNum of sprite dragChan to the castNum of sprite channel
  222.         set the locH of sprite channel to the locH of sprite dragChan
  223.         set the locV of sprite channel to the locV of sprite dragChan
  224.         set the locH of sprite dragChan to 1000
  225.         updateStage()
  226.         set the timeLinePos of tileObject to 0
  227.       end if
  228.     end repeat
  229.     set errorBuffer to []
  230.     set howManyCorrect to 0
  231.     repeat while soundBusy(0)
  232.     end repeat
  233.     puppetSound(0)
  234.     flushBuffer()
  235.   end if
  236. end
  237.  
  238. on turnDone me
  239.   set the locH of sprite originalChannel to the locH of sprite dragChan
  240.   set the locV of sprite originalChannel to the locV of sprite dragChan
  241.   removeSprite(dragChan)
  242.   updateStage()
  243.   set the constraint of sprite dragChan to 0
  244.   set dragFlag to 0
  245.   deleteAt(gActorList, getPos(gActorList, me))
  246.   showAllActors()
  247. end
  248.  
  249. on checkForSuccess me
  250.   if howManyCorrect = 9 then
  251.     startBuffering()
  252.     repeat while soundBusy(0)
  253.     end repeat
  254.     puppetSound(0)
  255.     sound playFile 1, gCDpath & "SOUND" & gFileSep & "GLOBAL" & gFileSep & "0820C"
  256.     giveAward(gAwardsObject, "VTL")
  257.     newVTLgame(me)
  258.     repeat while soundBusy(1)
  259.     end repeat
  260.     puppetSound(0)
  261.     goToVideo(me)
  262.     flushBuffer()
  263.   end if
  264. end
  265.  
  266. on predrawVTLgameTiles me
  267.   repeat with tileNum = 1 to count(tileList)
  268.     set tileObject to getAt(tileList, tileNum)
  269.     if the timeLinePos of tileObject = 0 then
  270.       set location to getAt(tilePointList, the scrambledPos of tileObject)
  271.     else
  272.       put the timeLinePos of tileObject
  273.       set location to getAt(targetPointList, the timeLinePos of tileObject)
  274.     end if
  275.     set bmap to firstTileBmap + tileNum - 1
  276.     set channel to firstTileChannel + the scrambledPos of tileObject - 1
  277.     set the castNum of sprite channel to bmap
  278.     set the locH of sprite channel to getAt(location, 1)
  279.     set the locV of sprite channel to getAt(location, 2)
  280.     set the ink of sprite channel to 36
  281.     if channel = the channel of gGasGaugeObject then
  282.       set the stretch of sprite the channel of gGasGaugeObject to 0
  283.       set the ink of sprite the channel of gGasGaugeObject to 36
  284.       set the foreColor of sprite the channel of gGasGaugeObject to 255
  285.     end if
  286.     puppetSprite(channel, 1)
  287.   end repeat
  288. end
  289.  
  290. on VTLgameTileHandler me
  291.   set whichTile to value(the name of cast the castNum of sprite the clickOn)
  292.   set tileObject to getAt(tileList, whichTile)
  293.   if the timeLinePos of tileObject = 0 then
  294.     puppetSound(getAt(the nameSoundList of gVTLobject, whichTile))
  295.     set selection to whichTile
  296.     set originalChannel to the clickOn
  297.     set bitmap to the castNum of sprite the clickOn
  298.     set the castNum of sprite dragChan to bitmap
  299.     puppetSprite(dragChan, 1)
  300.     puppetSprite(constrainChan, 1)
  301.     set the locH of sprite dragChan to the locH of sprite the clickOn
  302.     set the locV of sprite dragChan to the locV of sprite the clickOn
  303.     set the locH of sprite the clickOn to 1000
  304.     set the rect of sprite constrainChan to getBoundRect(bitmap, 0)
  305.     updateStage()
  306.     set the constraint of sprite dragChan to constrainChan
  307.     animateSprite(dragChan, point(the mouseH, the mouseV), 1)
  308.     set dragFlag to 1
  309.     puppetTempo(60)
  310.     add(gActorList, me)
  311.     hideOtherActors(me)
  312.   end if
  313. end
  314.  
  315. on goToVideo me
  316.   set videoName to "08.MOV"
  317.   set the videoName of gQTViewerObject to videoName
  318.   set paletteName to the name of cast (the number of cast videoName - 1)
  319.   set the paletteName of gQTViewerObject to paletteName
  320.   set the returnScript of gQTViewerObject to "returnFromQT( gVTLgameObject )"
  321.   set errorBuffer to []
  322.   clearAllActors()
  323.   unpuppetAll()
  324.   puppetPalette("VTLgamePal")
  325.   go("Grass")
  326.   go(the frame + 1)
  327.   puppetPalette(paletteName, 60)
  328.   updateStage()
  329.   puppetPalette(0)
  330.   unLoadCast()
  331.   go("QT20")
  332. end
  333.  
  334. on returnFromQT me
  335.   prepareToLeave(gQTViewerObject)
  336.   go("Grass")
  337.   go(the frame + 1)
  338.   unLoadCast()
  339.   goLocationMap()
  340. end
  341.  
  342. on goMenu me, buttonObject
  343.   set errorBuffer to []
  344.   clearAllActors()
  345.   unpuppetAll()
  346.   if objectp(buttonObject) then
  347.     makeButtonJump(buttonObject)
  348.   end if
  349.   puppetPalette("VTLgamePal")
  350.   go("Grass")
  351.   go(the frame + 1)
  352.   unLoadCast()
  353.   goLocationMap()
  354. end
  355.  
  356. on help me, buttonObject
  357.   set whichHelp to "VTLgame" & string(the level of gLevelObject)
  358.   birth(script "Help Parent", buttonObject, whichHelp)
  359. end
  360.